<template>
    <div>
        <el-form ref="queryForm" class="query-box" v-model="queryParams" :inline="true">
            <el-form-item label="商户编号" prop="merchantNo" label-width="120px">
                <el-input v-model="queryParams.merchantNo"
                          clearable
                          placeholder="请输入商户编号"
                          style="width: 240px"
                          size="small" @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <!-- <el-form-item label="姓名" prop="contactName" label-width="120px">
                <el-input v-model="queryParams.contactName"
                          clearable
                          placeholder="请输入姓名"
                          style="width: 240px"
                          size="small" @keyup.enter.native="handleQuery"/>
            </el-form-item> -->
            <el-form-item label="审核状态" prop="changeCheckStatus" label-width="120px">
                <el-select style="width:240px" v-model="queryParams.changeCheckStatus" size="small" placeholder="请选择审核状态">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="审核中" value="0"></el-option>
                    <el-option label="审核成功" value="1"></el-option>
                    <el-option label="审核失败" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="开通时间" prop="name" label-width="120px">
                <el-date-picker v-model="createDateRange"
                                size="small" value-format="yyyy-MM-dd"
                                type="daterange" range-separator="-"
                                style="width: 240px"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"/>
            </el-form-item>
            <!-- <el-form-item label="变更状态" prop="changeType" label-width="140px">
                <el-select v-model="queryParams.changeType" placeholder="请选择商户状态">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="待审核" value="1"></el-option>
                    <el-option label="审核失败" value="2"></el-option>
                    <el-option label="正常" value="3"></el-option>
                    <el-option label="注销" value="4"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审核状态" prop="changeCheckStatus" label-width="140px">
                <el-select v-model="queryParams.changeCheckStatus" placeholder="请选择商户状态">
                    <el-option label="全部" value=""></el-option>
                    <el-option label="待审核" value="1"></el-option>
                    <el-option label="审核失败" value="2"></el-option>
                    <el-option label="正常" value="3"></el-option>
                    <el-option label="注销" value="4"></el-option>
                </el-select>
            </el-form-item> -->
            <el-form-item label="提交时间" prop="name" label-width="120px">
                <el-date-picker v-model="updateDateRange"
                                size="small" value-format="yyyy-MM-dd"
                                type="daterange" range-separator="-"
                                style="width: 240px"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间"/>
            </el-form-item>

        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-search" size="mini"
                           @click="handleQuery" v-permission="'MER_CHANGE_APPLY_INFO_QUERY'">
                    查询
                </el-button>
                <el-button icon="el-icon-refresh" size="mini"
                           @click="handleResetQuery" v-permission="'MER_CHANGE_APPLY_INFO_QUERY'">
                    重置
                </el-button>
                <el-button type="primary" icon="el-icon-plus" size="mini"
                           @click="handleRateChange"
                           v-permission="'MER_CHANGE_APPLY_INFO_INSERT'">
                    费率变更
                </el-button>
                <el-button type="primary" icon="el-icon-plus" size="mini"
                           @click="handleSettleChange"
                           v-permission="'MER_CHANGE_APPLY_INFO_INSERT'">
                    结算卡变更
                </el-button>
                <!-- <el-button type="primary" icon="el-icon-plus" size="mini"
                           @click="handleStatusChange"
                           v-permission="'MER_CHANGE_APPLY_INFO_INSERT'">
                    状态变更
                </el-button> -->
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import {MerchantApi} from '@/api';
    export default {
        name: "ToolBar",
        props: {
            dicts: {
                type: Object,
                default: {}
            }
        },
        data() {
            return {
                queryParams: {},
                createDateRange: [],
                updateDateRange: [],
                showCustomForm: false,
            }
        },
        mounted() {
        },
        methods: {
            handlerCustomFormOnclose() {
                this.showCustomForm = false;
                this.commitChange();
            },
            handleQuery() {
                this.commitChange();
            },
            handleResetQuery(){
                this.queryParams = {};
                this.createDateRange = [];
                this.updateDateRange = [];
                this.commitChange();
            },
            handleRateChange(){
                this.$router.push({
                    name:'RateChangeApply',
                    query:{
                        isAdd:'1'
                    }
                })
            },
            handleSettleChange(){
                this.$router.push({
                    name:'SettleChangeApply',
                    query:{
                        isAdd:'1'
                    }
                })
            },
            handleStatusChange(){
                this.$router.push({
                    name:'StatusChangeApply',
                    query:{
                        isAdd:'1'
                    }
                })
            },
            handleExport() {
                this.$confirm("确定导出业务用户（包含机构/代理商）",
                        "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(async () => {
                    this.dealWithQueryParams();
                    let result = (await MerchantApi.agentInfo.export(this.queryParams));
                    if (result.success) {
                        this.downloadFile(result.data);
                    }
                });
            },
            dealWithQueryParams() {
                let [beginMerCreateTime, endMerCreateTime] = this.createDateRange;
                this.queryParams.beginMerCreateTime = beginMerCreateTime && (beginMerCreateTime + ' 00:00:00');
                this.queryParams.endMerCreateTime = endMerCreateTime && (endMerCreateTime + ' 23:59:59');

                let [beginChangeCreateTime, endChangeCreateTime] = this.updateDateRange;
                this.queryParams.beginChangeCreateTime = beginChangeCreateTime && (beginChangeCreateTime + ' 00:00:00');
                this.queryParams.endChangeCreateTime = endChangeCreateTime && (endChangeCreateTime + ' 23:59:59');
            },
            commitChange() {
                this.dealWithQueryParams();
                let params = {...this.queryParams};
                this.$emit('on-change', params);
            },
        }
    }
</script>

<style scoped>

</style>
